package com.controller;

/**
 * @program: honye-fang
 * @description:
 * @author: Baiyyy
 * @create: 2025-02-14 22:15
 **/


import com.entity.HyFurniture;
import com.service.HyFurnitureService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

@RestController
public class CacheController {


    @Autowired
    private HyFurnitureService hyFurnitureService;


//    @Resource
//    private RedisService redisService;

    // 将家具信息缓存到 Redis 中
//    public void cacheFurniture(Long furnitureId, HyFurniture furniture) {
//        // 将家具数据存入 Redis
//        redisService.redisTemplate.opsForValue().set("furniture:" + furnitureId, furniture);
//
//    }



    //每天凌晨2点将家具添加到缓存中

//    @Scheduled(cron = "0 0 2 * * ?")
//    public void addFurnitureToCache() {
//        // 将家具数据添加到 Redis
//        try {
//            List<HyFurniture> allFurniture = hyFurnitureService.getAllFurniture();
//            // 添加日志输出
//            System.out.println("定时任务执行，获取家具数量：" + allFurniture.size());
//            for (HyFurniture furniture : allFurniture) {
//                cacheFurniture(furniture.getId(), furniture);
//            }
//        } catch (Exception e) {
//            e.printStackTrace();
//        }
//
//    }


    //从缓存中获取家具信息
//    public HyFurniture getFurnitureFromCache(Long id) {
//        // 从 Redis 获取家具数据
//        return (HyFurniture) redisService.redisTemplate.opsForValue().get("furniture:" + id);
//    }


    }

